{{define "admin/seeexams.html"}}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
{{template "admin/commonlib.html"}}
    <title>TM - Class</title>

    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="/static/libs/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/static/libs/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="/static/libs/Ionicons/css/ionicons.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="/static/libs/datatables.net-bs/css/dataTables.bootstrap.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="/static/libs/AdminLTE/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="/static/libs/AdminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="/static/libs/bootstrap-notify-master/css/bootstrap-notify.css">
    <link rel="stylesheet" href="/static/libs/bootstrap-notify-master/css/styles/alert-blackgloss.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <![endif]-->
    <link rel="stylesheet" href="/static/libs/sweetalert/sweetalert.css" type="text/css"/>
    <link rel="stylesheet" href="/static/libs/jbox/jBox.css">
    <link rel="stylesheet" href="/static/libs/iCheck/flat/_all.css" type="text/css"/>
    <link rel="stylesheet" href="/static/libs/select2/css/select2.min.css" type="text/css"/>
    <link rel="stylesheet" href="/static/libs/daterangepicker/daterangepicker-bs3.css" type="text/css"/>
    <!-- Google Font -->
    <link rel="stylesheet" href="/static/font/Souce+Sans.css" type="text/css"/>
    <script src="/static/libs/moment/moment.min.js"></script>
    <style type="text/css">
        .addbtn {
            margin-left: 15px;
        }

        .btn-box-tool i.fa-times {
            font-size: 21px;
        }

        .config {
            margin-left: 31px;
        }

        .spinner1, .spinner2 {
            width: 100px;
        }

        .spinner1 input, .spinner2 input {
            text-align: right;
        }

        .input-group-btn-vertical {
            position: relative;
            white-space: nowrap;
            width: 1%;
            vertical-align: middle;
            display: table-cell;
        }

        .input-group-btn-vertical > .btn {
            display: block;
            float: none;
            width: 100%;
            max-width: 100%;
            padding: 8px;
            margin-left: -1px;
            position: relative;
            border-radius: 0;
        }

        .input-group-btn-vertical > .btn:first-child {
            border-top-right-radius: 4px;
        }

        .input-group-btn-vertical > .btn:last-child {
            margin-top: -2px;
            border-bottom-right-radius: 4px;
        }

        .input-group-btn-vertical i {
            position: absolute;
            top: 0;
            left: 4px;
        }

        .quesnum {
            margin-top: 5px;
        }

        .quesnuminput {
            margin-left: -15px;
        }

        .pull-rightnew {
            position: absolute;
            right: 10px;
            top: 5px;
        }

        .boxnew {
            width: 100%;
            margin-left: 0px;
        }

        .box {
            margin-bottom: 25px;
        }

    </style>

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <div class='notifications top-right'></div>
{{template "admin/navbar.html" .}}


    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- Sidebar user panel -->
            <div class="user-panel">
                <div class="pull-left image">
                {{if gt (len .user.AvatarUrl) 0}}
                    <img src="{{.user.AvatarUrl}}" class="img-circle" alt="User Image">
                {{else}}
                    <img src="/static/libs/AdminLTE/img/avastar.jpg" class="img-circle" alt="User Image">
                {{end}}
                </div>
                <div class="pull-left info">
                    <p>{{.user.Email}}</p>
                    <!--<a href="#"><i class="fa fa-circle text-success"></i> Online</a>-->
                </div>
            </div>
            <!-- sidebar menu: : style can be found in sidebar.less -->
            <ul class="sidebar-menu" data-widget="tree">
                <li class="header">MAIN NAVIGATION</li>
                <li class="treeview">
                    <a href="/admin/index">
                        <i class="fa fa-dashboard"></i> <span>总览</span>
                    </a>
                </li>


                <li class="treeview ">
                    <a href="#">
                        <i class="fa fa-th"></i>
                        <span>班级</span>
                        <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
                    </a>

                    <ul class="treeview-menu">
                        <li class="active"><a href="/admin/seeclass"><i class="fa fa-circle-o"></i> 查看班级</a></li>
                        <li><a href="/admin/managerclass"><i class="fa fa-circle-o"></i> 管理班级</a></li>
                    </ul>
                </li>


                <li class="treeview active">
                    <a href="#">
                        <i class="fa fa-laptop"></i>
                        <span>测试</span>
                        <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
                    </a>

                    <ul class="treeview-menu">
                        <li class="active"><a href="/admin/getexams"><i class="fa fa-circle-o"></i> 查看小测</a></li>
                        <li><a href="/admin/managerexam"><i class="fa fa-circle-o"></i> 管理小测</a></li>
                    </ul>
                </li>

                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-folder"></i>
                        <span>公告</span>
                        <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
                    </a>

                    <ul class="treeview-menu">
                        <li><a href="/admin/seenotice"><i class="fa fa-circle-o"></i> 查看公告</a></li>
                        <li><a href="/admin/managerclass"><i class="fa fa-circle-o"></i> 管理班级</a></li>
                    </ul>
                </li>
            </ul>
        </section>
        <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                <a class="btn btn-primary" href="" data-href="/admin/Autoexam"
                   data-toggle="modal" data-target="#confirm-delete">
                    <span class="glyphicon glyphicon-plus"></span>新增测试</a>
            </h1>
            <ol class="breadcrumb">
                <li><a href="/admin/getexams"><i class="fa fa-dashboard"></i>测试</a></li>
                <li class="active"><a href="#">查看测试</a></li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class=" row box boxnew">
                <div class="">
                    <div class=" callout callout-info">
                        <h4 class="unpublishexamstitle">有{{(len .unpublishexams)}}个未发布测试,右侧可收起</h4>

                    </div>
                </div>
                <div class="box-tools pull-rightnew">
                    <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                    </button>
                </div>
                <div class="unpubexams row box-body">
                {{range .unpublishexams}}
                    <div class="col-lg-3 col-xs-6">
                        <!-- small box -->
                        <div class="small-box box box-widget bg-aqua">
                            <input name="classid" type="hidden" value="{{.ExamID}}"/>
                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool" data-widget="remove"><i
                                        class="fa fa-times"></i></button>
                            </div>
                            <div class="inner">
                                <h3>{{.Title}}</h3>

                                <p>{{.DesCrib}}</p>
                            </div>

                            <a href="/admin/exam/{{.ExamID}}" class="small-box-footer">
                                详细内容 <i class="fa fa-arrow-circle-right"></i>
                            </a>
                        </div>
                    </div>
                {{end}}
                </div>
            {{/*<div class="overlay">*/}}
            {{/*<i class="fa fa-refresh fa-spin"></i>*/}}
            {{/*</div>*/}}
            </div>


            <div class="row box boxnew">
                <div class="">
                    <div class=" callout callout-success">
                        <h4 class="publishexamstitle">有{{(len .publishexams)}}个已发布测试,右侧可收起</h4>

                    </div>
                </div>

                <div class="box-tools pull-rightnew">
                    <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                    </button>
                </div>
                <div class="pubexams row box-body">
                {{range .publishexams}}
                    <div class="col-lg-3 col-xs-6">
                        <!-- small box -->
                        <div class="small-box box box-widget bg-green">
                            <input name="classid" type="hidden" value="{{.ExamID}}"/>
                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool" data-widget="remove"><i
                                        class="fa fa-times"></i></button>
                            </div>
                            <div class="inner">
                                <h3>{{.Title}}</h3>

                                <p>{{.DesCrib}}</p>
                                <p>测试时间:  {{.StartTime}} ~ {{.EndTime}}</p>
                            </div>

                            <a href="/admin/exam/{{.ExamID}}" class="small-box-footer">
                                详细内容 <i class="fa fa-arrow-circle-right"></i>
                            </a>
                        </div>
                    </div>
                {{end}}
                </div>

            </div>


        </section>

        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

</div>
<!-- ./wrapper -->

<div class="modal fade" id="confirm-delete" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                建立测试
            </div>
            <div class="modal-body">
                <form id="form_data" role="form" class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">测试名称</label>
                        <div class="col-sm-10">
                            <input name="testname" class="form-control">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">测试描述</label>
                        <div class="col-sm-10">
                            <textarea name="testdescri" class="form-control" rows="3"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">选择难度</label>
                        <div class="col-md-6">
                            <input name="selectdegree" type="checkbox">
                        </div>

                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">测试难度</label>
                        <div class="col-md-6">
                            <select disabled class="degree  form-control select2 select2-hidden-accessible"
                                    style="width: 100%;"
                                    tabindex="-1" aria-hidden="true">

                            </select>
                        </div>

                        <div class="col-sm-2">
                            <button type="button" class="tooltip ">换一个</button>
                            <div style="display: none" id="grabMe">
                                <div>
                                    简单: 2个运算数(整数)的加减运算 适合2~3年纪学生
                                </div>
                                <div>
                                    中等: 多个运算数(整数)的加减乘除运算，适合4~5年纪学生
                                </div>
                                <div>
                                    难度: 多个运算数(整数,分数,包括带分数,括号)的加减乘除 适合6年纪以及初中生
                                </div>
                            </div>
                        {{/*<button type="button" class="btn btn-block btn-info btn-sm">换一个</button>*/}}
                            <div class=""><i class="fa fa-fw fa-list-alt"></i> 说明</div>

                        </div>
                    </div>
                    <div class="form-group">
                        <div class="row">
                            <label class="col-sm-2 control-label">详细配置</label>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="config">
                                    <input name="selectconfigadd_sub" type="checkbox"> 加减

                                </div>

                                <div class="config">
                                    <input name="selectconfigmul_div" type="checkbox"> 乘除
                                </div>
                                <div class="config">
                                    <input name="selectconfigfraction" type="checkbox"> 分数(代分数)
                                </div>
                                <div class="config">
                                    <input name="selectconfigpt" type="checkbox"> 括号
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="row">
                                    <label class="col-sm-6 control-label">运算数范围</label>
                                    <div class="col-sm-6 input-group spinner1">
                                        <input type="text" name="calnums" class="form-control" value="3">
                                        <div class="input-group-btn-vertical">
                                            <button class="btn btn-default" type="button"><i class="fa fa-caret-up"></i>
                                            </button>
                                            <button class="btn btn-default" type="button"><i
                                                    class="fa fa-caret-down"></i>
                                            </button>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <label class="col-sm-6 control-label">运算符最大个数</label>
                                    <div class="col-sm-6 input-group spinner2">
                                        <input type="text" name="calcsim" class="form-control" value="3">
                                        <div class="input-group-btn-vertical">
                                            <button class="btn btn-default" type="button"><i class="fa fa-caret-up"></i>
                                            </button>
                                            <button class="btn btn-default" type="button"><i
                                                    class="fa fa-caret-down"></i>
                                            </button>
                                        </div>
                                    </div>
                                </div>
                                <div class="row quesnum">
                                    <label class="col-sm-6 control-label">题目数量</label>
                                    <div class="quesnuminput col-sm-4">
                                        <input name="quenums" class="form-control">
                                    </div>
                                </div>
                            </div>


                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" style="text-align:left;">是否现在发布</label>
                        <div class="col-md-6" style="margin-left: -46px">
                            <input name="ispublishnow" type="checkbox">
                        </div>
                    </div>
                    <div class="form-group" style="margin-left:5px;">
                        <label>起始时间至结束时间</label>

                        <div class="col-sm-10 input-group">
                            <div class="input-group-addon">
                                <i class="fa fa-clock-o"></i>
                            </div>
                            <input disabled type="text" class="timerange col-sm-6 form-control pull-right"
                                   id="reservationtime">
                        </div>

                    </div>

                    <div class="form-group" style="margin-left:-20px;">
                        <label class="col-sm-2 control-label">发布班级</label>
                        <div class="col-md-6">
                            <select disabled class="pubclasses  form-control select2 select2-hidden-accessible"
                                    style="width: 100%;"
                                    tabindex="-1" aria-hidden="true">

                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <a class="btn btn-primary btn-ok">确定</a>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="confirm-delete2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                请确认
            </div>
            <div class="modal-body">
                <form id="form_data" role="form" class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">输入账号密码</label>
                        <div class="col-sm-6">
                            <input name="password" class="form-control">
                        </div>
                        <div class="col-sm-2">
                            <button type="button" class="checkuser btn btn-block btn-info btn-sm">验证</button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default cancel" data-dismiss="modal">取消</button>
                <a class="disabled btn btn-danger btn-ok deleteclass">删除记录</a>
            </div>
        </div>
    </div>
</div>

<!-- jQuery 3 -->
<!-- Bootstrap 3.3.7 -->
{{template "admin/page_end.html"}}

{{/*<script src="/static/libs/bootstrap/js/bootstrap.min.js"></script>*/}}
<!-- DataTables -->
<script src="/static/libs/jbox/jBox.js"></script>
{{/*<script src="/static/libs/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>*/}}

<!-- AdminLTE App -->
<!-- page script -->
<script>
    var issave = false;
    //选择难度是否开启
    var selectdegree = false;
    //难度系数
    var degree = null;
    //加减 乘除 分数 括号
    var add_sub = false;
    var mul_div = false;
    var fraction = false;
    var pt = false;
    //题目数量
    // var quesnums = 0;
    var calnums = 0;
    var calcsim = 0;
    var ispublishnow = false;
    var data = {};
    var userid = {{.user.ID}}+"";
    var custom = [
        'bangTidy',
        'blackgloss'
    ];
    //Date range picker
    $('#reservation').daterangepicker();
    //Date range picker with time picker
    $('#reservationtime').daterangepicker({
        timePickerIncrement: 60, //时间的增量，单位为分钟
        opens: 'right', //日期选择框的弹出位置
        timePicker12Hour: false, //是否使用12小时制来显示时间
        ranges: {
            '最近1小时': [moment(), moment().add('hours', 1)],
            '今日内': [moment(), moment().add('days', 1).startOf('day')],
            '明日内': [moment().add('days', 1).startOf('day'), moment().add('days', 2).startOf('day')],
            '7日内': [moment(), moment().add('days', 6)],
            '30日内': [moment(), moment().add('days', 29)]
        },
        format: 'YYYY-MM-DD HH:mm',
        timePicker: true, timePickerIncrement: 30, "locale": {
            format: 'YYYY-MM-DD HH:mm',
            applyLabel: "应用",
            cancelLabel: "取消",
            resetLabel: "重置",
        }
    }, function (start, end, label) {
        //格式化日期显示框
        $('#searchDate').val(start.format('YYYY-MM-DD HH:mm') + '-' + end.format('YYYY-MM-DD HH:mm'));
    });
    //Date range as a button
    // $('#daterange-btn').daterangepicker(
    //         {
    //             ranges: {
    //                 'Today': [moment(), moment()],
    //                 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
    //                 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
    //                 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
    //                 'This Month': [moment().startOf('month'), moment().endOf('month')],
    //                 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
    //             },
    //             startDate: moment().subtract(29, 'days'),
    //             endDate: moment()
    //         },
    //         function (start, end) {
    //             $('#reportrange span').html(start.format('YYYY-MM-DD HH:mm') + '-' + end.format('YYYY-MM-DD HH:mm'));
    //         }
    // );
    (function ($) {
        $('.spinner1 .btn:first-of-type').on('click', function () {
            $('.spinner1 input').val(parseInt($('.spinner1 input').val(), 10) + 1);
        });
        $('.spinner1 .btn:last-of-type').on('click', function () {
            $('.spinner1 input').val(parseInt($('.spinner1 input').val(), 10) - 1);
        });
        $('.spinner2 .btn:first-of-type').on('click', function () {
            $('.spinner2 input').val(parseInt($('.spinner2 input').val(), 10) + 1);
        });
        $('.spinner2 .btn:last-of-type').on('click', function () {
            $('.spinner2 input').val(parseInt($('.spinner2 input').val(), 10) - 1);
        });
    })(jQuery);
    var data = [{id: 0, text: '简单'}, {id: 1, text: '中等'}, {id: 2, text: '困难'}];
    $(".degree").select2({
        data: data,
        placeholder: '请选择',
        allowClear: true
    });


    // $("#pubclasses").select2({
    //     ajax: {
    //         url: "data.json",
    //         dataType: 'json',
    //         delay: 250,
    //         data: function (params) {
    //             return {
    //                 q: params.term,
    //             };
    //         },
    //         processResults: function (data) {
    //             return {
    //                 results: data.res
    //             };
    //         },
    //         cache: true
    //     },
    //     escapeMarkup: function (markup) {
    //         return markup;
    //     },
    //     minimumInputLength: 1,
    //     templateResult: formatRepo,
    //     templateSelection: formatRepoSelection
    // });


    $(document).ready(function () {
        $('input[name="selectdegree"]').iCheck({
            checkboxClass: 'icheckbox_flat-blue',
            radioClass: 'iradio_flat-blue'
        }).on('ifChecked', function (event) {
            selectdegree = true;
            $('input[name="selectconfigadd_sub"]').iCheck('disable');
            $('input[name="selectconfigmul_div"]').iCheck('disable');
            $('input[name="selectconfigfraction"]').iCheck('disable');
            $('input[name="selectconfigpt"]').iCheck('disable');
            $('input[name="calnums"]').attr("disabled", true);
            $('input[name="calcsim"]').attr("disabled", true);
            $('input[name="quenums"]').attr("disabled", true);
            $(".degree ").prop("disabled", false)
        }).on('ifUnchecked', function (event) {
            selectdegree = false;
            $('input[name="selectconfigadd_sub"]').iCheck('enable');
            $('input[name="selectconfigmul_div"]').iCheck('enable');
            $('input[name="selectconfigfraction"]').iCheck('enable');
            $('input[name="selectconfigpt"]').iCheck('enable');
            $('input[name="selectconfig"]').iCheck('enable');
            $('input[name="calnums"]').attr("disabled", false);
            $('input[name="calcsim"]').attr("disabled", false);
            $('input[name="quenums"]').attr("disabled", false);
            $(".degree ").prop("disabled", true)

        });
        $('input[name="selectconfigadd_sub"]').iCheck({
            checkboxClass: 'icheckbox_flat-pink',
            radioClass: 'iradio_flat-pink'
        }).on('ifChecked', function (event) {
            add_sub = true
        }).on('ifUnchecked', function (event) {
            add_sub = false
        });
        $('input[name="selectconfigmul_div"]').iCheck({
            checkboxClass: 'icheckbox_flat-pink',
            radioClass: 'iradio_flat-pink'
        }).on('ifChecked', function (event) {
            mul_div = true
        }).on('ifUnchecked', function (event) {
            mul_div = false
        });
        $('input[name="selectconfigfraction"]').iCheck({
            checkboxClass: 'icheckbox_flat-pink',
            radioClass: 'iradio_flat-pink'
        }).on('ifChecked', function (event) {
            fraction = true
        }).on('ifUnchecked', function (event) {
            fraction = false
        });
        $('input[name="selectconfigpt"]').iCheck({
            checkboxClass: 'icheckbox_flat-pink',
            radioClass: 'iradio_flat-pink'
        }).on('ifChecked', function (event) {
            pt = true
        }).on('ifUnchecked', function (event) {
            pt = false
        });
        $('input[name="ispublishnow"]').iCheck({
            checkboxClass: 'icheckbox_flat-orange',
            radioClass: 'iradio_flat-orange'
        }).on('ifChecked', function (event) {
            ispublishnow = true;
            $('.timerange').attr("disabled", false);
            $('.pubclasses').attr("disabled", false);
        }).on('ifUnchecked', function (event) {
            ispublishnow = false;
            $('.timerange').attr("disabled", true);
            $('.pubclasses').attr("disabled", true);
        });

    });


    new jBox('Tooltip', {
        attach: '.tooltip',
        title: '难度系数区分',
        content: $('#grabMe'),
        position: {
            x: 'right',
        },
    });


    $('#confirm-delete2').on('show.bs.modal', function (e) {
        console.log("jinlaile");

        var classid = e.relatedTarget.classid;
        var _this = e.relatedTarget.remove;
        var mythis = e.relatedTarget.mythis;

        // alert(e.relatedTarget.classid);
        var delethis = $(this).find('.deleteclass');
        var checkthis = $(this).find('.checkuser');

        $(this).find('.checkuser').click(function () {
            var password = $('input[name="password"]').val();
            password = $.trim(password);
            console.log(password.length);
            if (password.length == 0) {
                $('.top-right').notify({
                    message: "密码不能为空",
                    type: custom[1]
                }).show();
                return
            }


            $.post("/admin/checkuser", {userid: userid, password: password}, function (result) {
                console.log(result);
                if (result.succeed) {
                    $('.top-right').notify({
                        message: {text: result.message},
                        type: custom[1]
                    }).show();
                    checkthis.unbind("click");
                    issave = true;
                    delethis.removeClass("disabled");
                } else {
                    $('.top-right').notify({
                        message: {text: result.message},
                        type: custom[1]
                    }).show();
                }
            }, 'json');

        });
        $(this).find('.deleteclass').click(function () {

            $.post("/admin/exam/delete", {examid: classid}, function (result) {
                console.log(result);
                if (result.succeed) {
                    $('.top-right').notify({
                        message: {text: result.message},
                        type: custom[1]
                    }).show();
                    $('input[name="password"]').val("");
                    $("#confirm-delete2").modal("hide");
                    delethis.addClass("disabled");
                    delethis.unbind("click");
                    if (result.ispublish) {
                        var str = $(".publishexamstitle").text();
                        var num = parseInt(str.substring(1)) -1;
                        $(".publishexamstitle").text("有" + num + "个已发布测试,右侧可收起");
                    } else {
                        var str = $(".unpublishexamstitle").text();
                        var num = parseInt(str.substring(1)) -1;
                        $(".unpublishexamstitle").text("有" + num + "个未发布测试,右侧可收起");
                    }


                    issave = false;
                    _this.remove(mythis);
                } else {
                    $('.top-right').notify({
                        message: {text: result.message},
                        type: custom[1]
                    }).show();
                }
            }, 'json');

        });
        $(this).find('.cancel').click(function () {
            delethis.unbind("click");
            checkthis.unbind("click");
        });

    });

    function checkNumber(theObj) {
        var reg = /^[0-9]+.?[0-9]*$/;
        if (reg.test(theObj)) {
            return true;
        }
        return false;
    }

    function getclasses(id) {
        $.get("/admin/getclasses", function (result) {
            console.log(result);
            if (result.succeed) {
                $(".pubclasses").select2({
                    data: result.classes,
                    placeholder: '请选择',
                    allowClear: true,
                    multiple: true
                });
            } else {
                $('.top-right').notify({
                    message: {text: '网络有问题,获取班级失败'},
                    type: custom[1]
                }).show();
                $('input[name="quenums"]').focus();
                return;
            }
        })
    }

    $('#confirm-delete').on('show.bs.modal', function (e) {
        console.log($(this));
        $(this).find('.btn-ok').unbind("click");
        getclasses(userid);
        $(this).find('.btn-ok').click(function () {
            var quesnums = 0
            var testname = $('input[name="testname"]').val();
            var testdescri = $('textarea[name="testdescri"]').val();
            var calnums = $('input[name="calnums"]').val();
            var calcsim = $('input[name="calcsim"]').val();
            var timerange = $('.timerange').val();
            quesnums = $('input[name="quenums"]').val();
            var res = $(".degree").select2("data")[0]; //单选
            var pubclassres = $(".pubclasses").select2("data"); //多选
            console.log(pubclassres)
            if (!checkNumber(quesnums) && (res.id == -1)) {
                $('.top-right').notify({
                    message: {text: '题目数量不合法！'},
                    type: custom[1]
                }).show();
                $('input[name="quenums"]').focus();
                return;
            }
            if (!testname) {
                $('.top-right').notify({
                    message: {text: '测试名称不能为空！'},
                    type: custom[1]
                }).show();
                $('input[name="testname"]').focus();
                return;
            }
            if (!timerange && ispublishnow) {
                $('.top-right').notify({
                    message: {text: '发布时间不能为空！'},
                    type: custom[1]
                }).show();
                // $('input[name="testname"]').focus();
                return;
            }
            if ((pubclassres.length == 0) && ispublishnow) {
                $('.top-right').notify({
                    message: {text: '发布班级不能为空'},
                    type: custom[1]
                }).show();
                // $('input[name="testname"]').focus();
                return;
            }

            console.log(selectdegree);
            if (!selectdegree && (!quesnums || (!add_sub && !mul_div && !fraction && !pt))) {
                $('.top-right').notify({
                    message: {text: '配置参数不够,请重新输入'},
                    type: custom[1]
                }).show();
                // $('input[name="testname"]').focus();
                return;
            }


            // if (!content) {
            //     alert("请填写内容");
            //     return;
            // }
            var data = {
                testname: testname,
                testdescri: testdescri,
            };

            if (ispublishnow) {
                data["time"] = timerange;
                var ids = [];
                for (var j = 0; j < pubclassres.length; j++) {
                    ids.push(pubclassres[j].id)
                }
                data["pubclass"] = ids.join(",");
            } else {
                data["time"] = "";
                data["pubclass"] = "";
            }
            if (selectdegree) {
                data["degree"] = res.id
            } else {
                data["degree"] = -1
            }
            data["add_sub"] = add_sub;
            data["mul_div"] = mul_div;
            data["fraction"] = fraction;
            data["pt"] = pt;
            data["quesnums"] = quesnums;
            data["calnums"] = calnums;
            data["calcsim"] = calcsim;
            console.log(data);
            $.post($(e.relatedTarget).data('href'), data, function (result) {
                console.log(result);
                var color = "bg-aqua";
                var time = "";
                if (result.succeed) {
                    swal({
                        title: "成功",
                        text: "跳转到班级查看页",
                        type: "success",
                        timer: 2000,
                        showConfirmButton: false
                    });
                    if (ispublishnow) {
                        color = "bg-green";
                        time = "<p>测试时间:  " +
                                result.exam.StartTime
                                + " ~ " +
                                result.exam.EndTime
                                + "</p>\n"
                    }
                    var demo_settings = $("<div />", {"class": 'col-lg-3 col-xs-6'});

                    demo_settings.append(
                            // 插入的元素

                            "                        <!-- small box -->\n" +
                            "                        <div class='small-box box box-widget " +
                            color
                            + "'>\n" +
                            "                            <input name='classid' type='hidden' value='" +
                            result.exam.ExamID
                            + "'/>\n" +
                            "                            <div class='box-tools pull-right'>\n" +
                            "                                <button type='button' class='btn btn-box-tool' data-widget='remove'><i\n" +
                            "                                        class='fa fa-times'></i></button>\n" +
                            "                            </div>\n" +
                            "                            <div class='inner'>\n" +
                            "                                <h3>" +
                            result.exam.Title
                            + "</h3>\n" +
                            "\n" +
                            "                                <p>" +
                            result.exam.DesCrib
                            + "</p>\n" +
                            time +
                            "                            </div>\n" +
                            "\n" +
                            "                            <a href='/admin/exam/" +
                            result.exam.ExamID
                            + "' class='small-box-footer'>\n" +
                            "                                详细内容 <i class='fa fa-arrow-circle-right'></i>\n" +
                            "                            </a>\n" +
                            "                        </div>\n"
                    );
                    $('#confirm-delete').modal("hide");
                    if (ispublishnow) {
                        $(".pubexams").append(demo_settings);
                        var str = $(".publishexamstitle").text();
                        var num = parseInt(str.substring(1)) + 1;
                        $(".publishexamstitle").text("有" + num + "个已发布测试,右侧可收起");
                    } else {
                        $(".unpubexams").append(demo_settings);
                        var str = $(".unpublishexamstitle").text();
                        var num = parseInt(str.substring(1)) + 1;
                        $(".unpublishexamstitle").text("有" + num + "个未发布测试,右侧可收起");
                    }

                } else {
                    $('.top-right').notify({
                        message: {text: "建立失败，原因：" + result.message},
                        type: custom[1]
                    }).show();
                }
            }, 'json');
        });
    });
    // $(function () {
    //     $('#example2').DataTable({
    //         'paging': true,
    //         'lengthChange': false,
    //         'searching': false,
    //         'ordering': true,
    //         'info': true,
    //         'autoWidth': false
    //     });
    // });


</script>
</body>
</html>
{{end}}